/*
* Copyright 2016 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-dealerApp-open-api
*
* @File name : DealerAppHomePageController.java
*
* @Author : WangHuicheng
*
* @Date : 2016年11月21日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016年11月21日    WangHuicheng    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmmc.dealerApp.api.controller;

import java.util.HashMap;
import java.util.Map;

import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.marketing.common.constants.ResultMsgConstants;
import org.marketing.common.dto.customerInfo.LoveModel4SaleDto;
import org.marketing.common.dto.customerInfo.PuserOwnerRelationDto;
import org.marketing.common.dto.customerInfo.TlNormalFollowRecodeDto;
import org.marketing.common.dto.search.DealerAppSearchDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmmc.dealerApp.api.constant.DealerAppConstant;
import com.yonyou.gmmc.dealerApp.api.service.CustomerInfoService;

/**
* DealerApp用户试乘试驾信息
* @author WangHuicheng

* @date 2016年11月21日
*/
@RestController
@RequestMapping(value = DealerAppConstant.BASE_PATH+"/customer")
public class DealerAppCustomerInfoController {
    private Logger  logger = Logger.getLogger(DealerAppCustomerInfoController.class);

    
//    @Autowired
//    CallCustomerInfoServiceInterface callCustomerInfoServiceInterface;
    @Autowired
    private CustomerInfoService callCustomerInfoServiceInterface;
    
    /**
     * 销售的客户信息检索
     * 
     * @author WangHuicheng
     * @date 2016年12月13日
     * @param dealerAppSearchDto
     * @return
     */
    @RequestMapping(value="/potentialSearch",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> getPotentialSearch(@RequestBody() DealerAppSearchDto dealerAppSearchDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            if (1 == dealerAppSearchDto.getClientType()) {
              result = callCustomerInfoServiceInterface.getPotentialUserList(dealerAppSearchDto);
            } else if (2 == dealerAppSearchDto.getClientType()){
                // 销售顾问ID
                dealerAppSearchDto.setSalesConsultantId(null);
                result = callCustomerInfoServiceInterface.getNotBindSales(dealerAppSearchDto);
            } else {
                this.logger.info("参数错误：ClientType："+dealerAppSearchDto.getClientType());
                result.put(ResultMsgConstants.RESULT_CODE, ResultMsgConstants.RESULT_CODE_ERROR);
                result.put(ResultMsgConstants.ERR_MSG, "参数错误：ClientType："+dealerAppSearchDto.getClientType());
            }
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 销售的已有客户信息车主客户信息
    * @author WangHuicheng
    * @date 2016年12月9日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value="/potentialUserList",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object>getPotentialUserList(@RequestBody() DealerAppSearchDto dealerAppSearchDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.getPotentialUserList(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 保存常规跟进记录
    *
    * @author WangHuicheng
    * @date 2016年12月4日
    * @param tlNormalFollowRecodeDto
    * @return
    * @throws Exception
     */
    @RequestMapping(value ="/insertTlNormalFollowRecode",method = RequestMethod.POST,consumes="application/json;charset=UTF-8",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public  Map<String,Object> insertTlNormalFollowRecode(@RequestBody @Valid TlNormalFollowRecodeDto tlNormalFollowRecodeDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.insertTlNormalFollowRecode(tlNormalFollowRecodeDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    
    
    /**
     * 删除心仪车型
    *
    * @author WangHuicheng
    * @date 2016年12月4日
    * @param loveModelId
    * @return
     */
    @RequestMapping(value ="/deleteLoveModel",method = RequestMethod.POST,consumes="application/json;charset=UTF-8",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> deleteLoveModel(@RequestBody LoveModel4SaleDto loveModel4SaleDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.deleteLoveModel(loveModel4SaleDto);
            result.put(ResultMsgConstants.RESULT_CODE, ResultMsgConstants.RESULT_CODE_SUCCESS);
            result.put(ResultMsgConstants.ERR_MSG, "");
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, ResultMsgConstants.RESULT_CODE_ERROR);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 保养到期提醒
    * @author WangHuicheng
    * @date 2016年12月9日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value="/maintainWarning",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object>getMaintainWarning(@RequestBody() DealerAppSearchDto dealerAppSearchDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.getMaintainWarning(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 保养到期提醒
    * @author WangHuicheng
    * @date 2016年12月9日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value="/insuranceWarning",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object>getInsuranceWarning(@RequestBody() DealerAppSearchDto dealerAppSearchDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.getInsuranceWarning(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 售后客户全部检索
    * @author WangHuicheng
    * @date 2016年12月9日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value="/customerList",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object>getcustomerList(@RequestBody() DealerAppSearchDto dealerAppSearchDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.getCustomerList(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    
    /**
     * 
    * 售后客户
    * @author WangHuicheng
    * @date 2016年12月9日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value="/customerSearch",method=RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> getCustomerSearch(@RequestBody() DealerAppSearchDto dealerAppSearchDto) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            // 已经存在客户检索
            if (1 == dealerAppSearchDto.getClientType()) {
                // 保养
                if (1 == dealerAppSearchDto.getSearchType()) {
                    result = callCustomerInfoServiceInterface.getMaintainWarning(dealerAppSearchDto);
                    // 保险
                } else if (2 == dealerAppSearchDto.getSearchType()) {
                    result = callCustomerInfoServiceInterface.getInsuranceWarning(dealerAppSearchDto);
                    // 全部
                } else if (9 == dealerAppSearchDto.getSearchType()) {
                    result = callCustomerInfoServiceInterface.getCustomerList(dealerAppSearchDto);
                    //result.put("getMaintainWarning", callCustomerInfoServiceInterface.getMaintainWarning(dealerAppSearchDto));
                    //result.put("getInsuranceWarning", callCustomerInfoServiceInterface.getInsuranceWarning(dealerAppSearchDto));
                } else {
                    this.logger.info("输入参数错误：" + "SearchType:" + dealerAppSearchDto.getSearchType());
                    result.put(ResultMsgConstants.RESULT_CODE, ResultMsgConstants.RESULT_CODE_SUCCESS);
                    result.put(ResultMsgConstants.ERR_MSG, "检索参数出错：SearchType:" + dealerAppSearchDto.getSearchType());
                }
            }
            // 未绑定服务顾问的潜在客户检索
            else if (2 == dealerAppSearchDto.getClientType()){
                // 保养到期提醒
                if (1 == dealerAppSearchDto.getSearchType()) {
                    result = callCustomerInfoServiceInterface.getNotBindMaintainWarning(dealerAppSearchDto);
                    // 保险到期提醒
                } else if (2 == dealerAppSearchDto.getSearchType()) {
                    result = callCustomerInfoServiceInterface.getNotBindInsuranceWarning(dealerAppSearchDto);
                    // 全部
                } else if (9 == dealerAppSearchDto.getSearchType()) {
                    result = callCustomerInfoServiceInterface.getNotBindAfterSales(dealerAppSearchDto);
                } else {
                    this.logger.info("输入参数错误：" + "SearchType:" + dealerAppSearchDto.getSearchType());
                    result.put(ResultMsgConstants.RESULT_CODE, ResultMsgConstants.RESULT_CODE_SUCCESS);
                    result.put(ResultMsgConstants.ERR_MSG, "检索参数出错：SearchType:" + dealerAppSearchDto.getSearchType());
                }
            } else {
                this.logger.info("输入参数错误：" + "clientType:" + dealerAppSearchDto.getClientType());
                result.put(ResultMsgConstants.RESULT_CODE, ResultMsgConstants.RESULT_CODE_SUCCESS);
                result.put(ResultMsgConstants.ERR_MSG, "检索参数出错：ClientType:" + dealerAppSearchDto.getClientType());
            }

        } catch (Exception e) {
            this.logger.info("错误详细：", e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 售后未绑定销售顾问的潜在客户保养预约提醒检索
    * @author WangHuicheng
    * @date 2016年12月13日
    * @param dealerAppSearchDto
    * @return
    * @throws Exception
     */
    @RequestMapping(value = "/notBindMaintainWarning", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> getNotBindMaintainWarning(@RequestBody DealerAppSearchDto dealerAppSearchDto) {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.getNotBindMaintainWarning(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 售后未绑定销售顾问的潜在客户保险预约提醒检索
    * @author WangHuicheng
    * @date 2016年12月13日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value = "/notBindInsuranceWarning", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> getNotBindInsuranceWarning(@RequestBody DealerAppSearchDto dealerAppSearchDto) {
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.getNotBindInsuranceWarning(dealerAppSearchDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
    
    /**
     * 
    * 潜在客户（抢）销售
    * @author WangHuicheng
    * @date 2016年12月9日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value = "/rushSalesCustomer", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> rushPotential(@RequestBody() PuserOwnerRelationDto puserOwnerRelationDto) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = callCustomerInfoServiceInterface.rushSalesCustomer(puserOwnerRelationDto);

        } catch (Exception e) {
            this.logger.info("错误详细：", e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;

    }
    /**
     * 
    * 潜在客户（抢）售后
    * @author WangHuicheng
    * @date 2016年12月14日
    * @param puserOwnerRelationDto
    * @return
     */
    @RequestMapping(value = "/rushAfterSalesCustomer", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> rushAfterSalesCustomer(@RequestBody() PuserOwnerRelationDto puserOwnerRelationDto) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = callCustomerInfoServiceInterface.rushAfterSalesCustomer(puserOwnerRelationDto);

        } catch (Exception e) {
            this.logger.info("错误详细：", e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;

    }
    
    /**
     * 
    *  售后新增潜客检索
    * @author WangHuicheng
    * @date 2016年12月11日
    * @param dealerAppSearchDto
    * @return
     */
    @RequestMapping(value = "/notBindAfterSales", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> getNotBindAfterSales(@RequestBody DealerAppSearchDto dealerAppSearchDto) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = callCustomerInfoServiceInterface.getNotBindAfterSales(dealerAppSearchDto);

        } catch (Exception e) {
            this.logger.info("错误详细：", e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;

    }
    
    
    /**
     * 销售新增潜客检索
     * 
     * @author WangHuicheng
     * @date 2016年12月11日
     * @param dealerAppSearchDto
     * @return
     */
    @RequestMapping(value = "/notBindSales", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String, Object> getNotBindSales(@RequestBody DealerAppSearchDto dealerAppSearchDto) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            result = callCustomerInfoServiceInterface.getNotBindSales(dealerAppSearchDto);

        } catch (Exception e) {
            this.logger.info("错误详细：", e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;

    }
    
    
    /**
     * 车主保存常规跟进记录
    *
    * @author WangHuicheng
    * @date 2016年12月16日
    * @param tlNormalFollowRecodeDto
    * @return
    * @throws Exception
     */
    @RequestMapping(value ="/insertCarOwnerFollowRecode",method = RequestMethod.POST,consumes="application/json;charset=UTF-8",produces = "application/json;charset=UTF-8")
    @ResponseBody
    public  Map<String,Object> insertCarOwnerFollowRecode(@RequestBody @Valid TlNormalFollowRecodeDto tlNormalFollowRecodeDto){
        Map<String,Object> result = new HashMap<String,Object>();
        try{
            result = callCustomerInfoServiceInterface.insertCarOwnerFollowRecode(tlNormalFollowRecodeDto);
        } catch(Exception e){
            this.logger.info("错误详细：",e);
            result.put(ResultMsgConstants.RESULT_CODE, 0);
            result.put(ResultMsgConstants.ERR_MSG, e.getMessage());
        }
        return result;
    }
}
